﻿/**
 *
 */
function soapWrapFunc(bdStr){
    // 封装SOAP头尾
    var soapHead = '<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://Webservice.zjusc.edu.cn/"><env:Body>', soapTail = '</env:Body></env:Envelope>';
    return soapHead + bdStr + soapTail;
}

//Ajax交付函数
function ajaxDispatcher(svcName, orderStr, funcObj){
    $.ajax({
        type: 'POST',
        contentType: 'text/xml',
        url: '../../Service/' + svcName,
        data: soapWrapFunc(orderStr),
        dataType: 'xml',
        success: funcObj,
        beforeSend: function(xhr){
            xhr.setRequestHeader("SOAPAction", "\"\"");
        },
        error: function(x, e){
            if (x.responseText.indexOf('oops') >= 0) {
                alert('您的权限认证失败，可能是密码已经泄露，请退出重新登录或联系管理员');
                return;
            }
            else {
                alert('error:' + x.responseText);
            }
        }
    });
}

$(function(){

});
/*
 *
 *
 */
$(window).load(function(){
    //获得报名号
    var stuApplyID = Tr0j4n.Cookie.Get('stuApplyID');
    var examFunc = function(xml){
        var tableHtml = '';
        $.each($(xml).find('item'), function(i, n){
			var dateReg = /\d{4}\-\d{2}\-\d{2}/,timeReg=/[0-2]{1}[0-6]{1}\:[0-5]{1}[0-9]{1}\:[0-5]{1}[0-9]{1}/;
            var eDate = $(xml).find('startTime').text(),duration=parseInt($(xml).find('duration').text()),dateVal=eDate.match(dateReg),timeVal=eDate.match(timeReg),dateTimeVal=dateVal+' '+timeVal;
            var timeRough = new Date(dateTimeVal.replace(new RegExp('-', 'g'), '/'));
			timeRough.setMinutes(timeRough.getMinutes() + duration, timeRough.getSeconds(), 0);
			tableHtml += (i % 2 != 0) ? '<tr>' : '<tr class="odd">';
            tableHtml += '<td>' + dateVal + '</td>';
            tableHtml += '<td>' + $(this).find('subject').text() + '</td>';
            tableHtml += '<td>' +  timeRough.toLocaleTimeString()+ '</td>';
            tableHtml += '</tr>';
        });
        
        $('#examInfoTable tbody').html(tableHtml);
        
    }
    var placeFunc = function(xml){
        var roomNum = $(xml).find('stuext_roomID').text();
        $('#epSpot').text($(xml).find('stuext_detailAddress').text());
        $('#epRoomNo').text(roomNum);
        $('#epSeatNo').text($(xml).find('stuext_seatNumber').text());
        var examstr = '<web:GetAllExamInfoByRoomNum><RoomNum>' + roomNum + '</RoomNum></web:GetAllExamInfoByRoomNum>';
        ajaxDispatcher('ExamService', examstr, examFunc);
    }
    var sendstr = '<web:GetStudentExtendInfoById><id>' + stuApplyID + '</id></web:GetStudentExtendInfoById>';
    
    ajaxDispatcher('StudentService', sendstr, placeFunc);
    
});
